package base;

import android.content.Context;
import android.util.Log;


import com.j256.ormlite.dao.Dao;

import java.util.List;
import java.util.UUID;

import javabean.Life_Login_UserInfo;


/**
 * Created by luoliwen on 16/4/28.
 * 用户注册信息
 */
public class Z_Login_UserInfoDao {
    private Context context;
    private Dao<Life_Login_UserInfo, Integer> userDao;
    private Z_DataBaseHelper helper;

    public Z_Login_UserInfoDao(Context context) {
        this.context = context;
        helper = Z_DataBaseHelper.getInstance(context);
        try {
            userDao = helper.getDao(Life_Login_UserInfo.class);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void addUser(String account, String password
    ) {
        try {
            Life_Login_UserInfo user = new Life_Login_UserInfo();
            user.setId(UUID.randomUUID().toString());
            user.setAccount(account);
            user.setPassword(password);
            userDao.create(user);

        } catch (Exception e) {
            Log.e("888", "xx" + e);
            e.printStackTrace();
        }
    }


    List<Life_Login_UserInfo> getId;

    public int getID(String account) {
        try {
            getId = userDao.queryBuilder().where().eq("account", account).query();
            return getId.size();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    List<Life_Login_UserInfo> account1;

    public List<Life_Login_UserInfo> queryForAll() {
        try {
            account1 = userDao.queryForAll();


        } catch (Exception e) {
            e.printStackTrace();
        }
        return account1;
    }

    public void delete() {
        try {
            Life_Login_UserInfo account1 = userDao.queryForAll().get(0);
            userDao.delete(account1);


        } catch (Exception e) {
            e.printStackTrace();

        }

    }

    public void deletes() {
        try {

            List<Life_Login_UserInfo> account1 = userDao.queryForAll();
            userDao.delete(account1);


        } catch (Exception e) {
            e.printStackTrace();

        }

    }

    public void delete(Life_Login_UserInfo account1) {
        try {

            userDao.delete(account1);


        } catch (Exception e) {
            e.printStackTrace();

        }

    }

}
